#include <iostream>
using namespace std;

int n,a[1000],cnt = 1;
string s;

struct Node{
    int data;
    struct Node *l,*r;
    Node(int d):data(d),l(NULL),r(NULL){}
};

int t = 1;
Node *preCreate(){
    if(t>=cnt||a[t]==-1)    return NULL;
    Node *root = new Node(a[t]);
    if(t+1<cnt){
        t++;
        root->l = preCreate();
    }
    if(t+1<cnt){
        t++;
        root->r = preCreate();
    }
    return root;
}

int flag = 0;
void postOrder(Node *root){
    if(root->l)    postOrder(root->l);
    if(root->r)    postOrder(root->r);
    if(flag)    cout<<" ";
    cout<<root->data;
    flag = 1;
}

signed main()
{
    for(int i=0;i<1000;i++)    a[i] = -1;
    cin>>n;
    getline(cin,s);
    while(getline(cin,s)){
        if(s[1]=='u')    a[cnt++] = (int)stoi(s.substr(5,s.size()-5));
        else    a[cnt++] = -1;
    }
    Node *root = preCreate();
    postOrder(root);
    return 0;
}
